# -*- coding: utf-8 -*-
"""
创建日期: 2024/9/17   18:39

@author: justinc
@blog: https://blog.csdn.net/sjc122333?type=blog
@gitee: https://gitee.com/justinc666

"""
from abc import ABCMeta, abstractmethod


# 接口
class Payment(metaclass=ABCMeta):
    @abstractmethod
    def pay(self, money):
        pass


class Alipay(Payment):
    def pay(self, money):
        print(f"支付宝付款{money}元。")


class Wechat(Payment):
    def __init__(self, xyhf=False):
        self.xyhf = xyhf

    def pay(self, money):
        if self.xyhf:
            print(f"先用后付支付{money}元。")
        else:
            print(f"微信支付{money}元。")


class PaymentFactory:
    def payment(self, method):
        if method == "支付宝":
            return Alipay()
        elif method == "微信":
            return Wechat()
        elif method == "微信先用后付":
            return Wechat(xyhf=True)
        else:
            raise TypeError("没有匹配的支付对象")


pf = PaymentFactory()
p = pf.payment("微信先用后付")
p.pay(100)
